package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.PmsBrandMapper;
import com.mall.pojo.PmsBrand;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsBrandApiAmpl implements PmsBrandApi {

    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    //添加品牌
    @Override
    public void create(PmsBrand pmsBrand) {
        pmsBrandMapper.insert(pmsBrand);
    }

    //删除品牌
    @Override
    public void delete(Integer id) {
        pmsBrandMapper.deleteById(id);
    }

    //更新品牌
    @Override
    public void update(Integer id, PmsBrand pmsBrand) {
        LambdaQueryWrapper<PmsBrand> wapper = new LambdaQueryWrapper<>();
        wapper.eq(PmsBrand::getId, id);
        pmsBrandMapper.update(pmsBrand, wapper);
    }

    //根据编号查询品牌信息
    @Override
    public PmsBrand selectById(Integer id) {
        return pmsBrandMapper.selectById(id);
    }

    //批量删除品牌
    @Override
    public void batch(List<Integer> ids) {
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PmsBrand::getId, ids);
        pmsBrandMapper.delete(wrapper);
    }

    //批量更新显示状态
    @Override
    public void showStatus(List<Integer> ids, Integer showStatus) {
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PmsBrand::getId, ids);
        PmsBrand pmsBrand = new PmsBrand();
        pmsBrand.setShowStatus(showStatus);
        pmsBrandMapper.update(pmsBrand, wrapper);
    }

    //批量更新厂家制造商状态
    @Override
    public void factoryStatus(List<Integer> ids, Integer factoryStatus) {
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PmsBrand::getId, ids);
        PmsBrand pmsBrand = new PmsBrand();
        pmsBrand.setFactoryStatus(factoryStatus);
        pmsBrandMapper.update(pmsBrand, wrapper);
    }

    //获取全部品牌列表
    @Override
    public List<PmsBrand> listAll() {
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        return pmsBrandMapper.selectList(wrapper);
    }

    //根据品牌名称分页获取品牌列表
    @Override
    public Page<PmsBrand> list(Integer pageNum, Integer pageSize, String keyword) {
        //创建分页对象，设置分页参数
        //注意：使用分页，需要配置分页插件！！！
        Page<PmsBrand> pg = new Page<>(pageNum, pageSize);

        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(keyword != null, PmsBrand::getName, keyword);
       return pmsBrandMapper.selectPage(pg, wrapper);

    }


}
